﻿{% extends "gma/base.html" %}
{% load mytag %}

<!-- CONTENT
  =====================================================================-->

{% block content %}

<div class="page__hd">
    <h1 class="page__title">{{ user.nickname }}</h1>
    <p class="page__desc">个人相册</p>
</div>

<div class="page__bd">
    <div class="weui-gallery" id="gallery">
        <span class="weui-gallery__img" id="galleryImg"></span>
        <div class="weui-gallery__opr">
            <a href="javascript:" class="weui-gallery__del">
                <i class="weui-icon-delete weui-icon_gallery-delete"></i>
            </a>
        </div>
    </div>

    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <div class="weui-uploader">
                    <div class="weui-uploader__hd">
                        <p class="weui-uploader__title">个人相册</p>
                        <div class="weui-uploader__info">{{ user.images|length }}</div>
                    </div>
                    <div class="weui-uploader__bd">
                        <ul class="weui-uploader__files" id="uploaderFiles">
                            {% for image in user.images %}
                            <li class="weui-uploader__file" style="background-image:url({{ image|cdn }})"></li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

{#    {% if auth_images|length > 0 %}#}
{#    <div class="weui-cells weui-cells_form">#}
{#        <div class="weui-cell">#}
{#            <div class="weui-cell__bd">#}
{#                <div class="weui-uploader">#}
{#                    <div class="weui-uploader__hd">#}
{#                        <p class="weui-uploader__title">审核相册</p>#}
{#                        <div class="weui-uploader__info">{{ user.auth_images|length }}</div>#}
{#                    </div>#}
{#                    <div class="weui-uploader__bd">#}
{#                        <ul class="weui-uploader__files" id="uploaderFiles2">#}
{#                            {% for image in auth_images %}#}
{#                            <li class="weui-uploader__file" style="background-image:url({{ image|cdn }})"></li>#}
{#                            {% endfor %}#}
{#                        </ul>#}
{#                    </div>#}
{#                </div>#}
{#            </div>#}
{#        </div>#}
{#    </div>#}
{##}
{#    <div class="weui-form-preview__ft">#}
{#        <a class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:reject()"> 拒绝 </a>#}
{#        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:agree()"> 同意 </a>#}
{#    </div>#}
{#    {% endif %}#}
</div>

<div class="page__ft">
    <a href="{% url 'gma:home' %}">
        <span class="bottom-logo">
           HiBao
       </span>
    </a>
</div>

{% endblock content %}

<!-- SCRIPT
  =====================================================================-->

{% block extra_js %}
<script type="text/javascript">
    $(function(){
        var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)"></li>',
            $gallery = $("#gallery"), $galleryImg = $("#galleryImg"),
            $uploaderInput = $("#uploaderInput"),
            $uploaderFiles = $("#uploaderFiles"),
            $uploaderFiles2 = $("#uploaderFiles2")
            ;

        $uploaderInput.on("change", function(e){
            var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
            for (var i = 0, len = files.length; i < len; ++i) {
                var file = files[i];

                if (url) {
                    src = url.createObjectURL(file);
                } else {
                    src = e.target.result;
                }

                $uploaderFiles.append($(tmpl.replace('#url#', src)));
            }
        });
        $uploaderFiles.on("click", "li", function(){
            $galleryImg.attr("style", this.getAttribute("style"));
            $gallery.fadeIn(100);
        });
        $uploaderFiles2.on("click", "li", function(){
            $galleryImg.attr("style", this.getAttribute("style"));
            $gallery.fadeIn(100);
        });
        $gallery.on("click", function(){
            $gallery.fadeOut(100);
        });
    });
</script>

{% if auth_images|length > 0 %}
<script>
function agree() {
    let url = "{% url 'gma:api_agree_photo' %}";
    let data = {
        'photo_id': {{ photo.id }},
    };

    new my_ajax(url, data, '', '', () => {
        show_toast("同意该图片上架!");
        window.history.back();
    });
}

function reject() {
    let url = "{% url 'gma:api_reject_photo' %}";
    let data = {
        'photo_id': {{ photo.id }},
    };

    new my_ajax(url, data, '', '', () => {
        show_toast("拒绝该图片上架!");
        window.history.back();
    });
}
</script>
{% endif %}

{% endblock extra_js %}